home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
FREENET
/
BLOCH
/
SOCKE14S
/
c
/
socketeer
< prev
Wrap
Text File
|
1998-12-09
|
19KB
|
604 lines
//#define MemCheck_MEMCHECK 1
//#include "MemCheck:MemCheck.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "toolbox.h"
#include "event.h"
#include "gadgets.h"
#include "iconbar.h"
#include "menu.h"
#include "wimplib.h"
#include "window.h"
#include "quit.h"
#include "proginfo.h"
#include "version.h"
#include "misc.h"
#include "connect.h"
#include "serial.h"
#include "setup.h"
#include "foh.h"
#include "launcher.h"
#include "ping.h"
#include "debug.h"
#include "bconsts.h"
extern MessagesFD msg_block={0,0,0,0};
static IdBlock id_block;
ObjectId AddWin, ConnMenu, ControlWin, DisconnWin, FingerWin, FriendsWin, IconBar, IconMenu, IdleWin, LauncherWin, MessageWin, PasswordWin, ProgInfo, RenameWin, SetupAccoun, SetupConnec, SetupEther, SetupFE, SetupFinger, SetupTCPIP, SetupLaunch, SetupMenu, SetupModem, SetupWin, StatsWin;
static BBox Q2_onscreen, Q2_offscreen;
static int task_handle = 0, current_wimp = 0, interested = 0;
//init_setup = 0;
static int timer_start_time = 0;
static int first_time_init = 0;
static int dialogue_timeout = 0;
static char directory[32] = "<Socketeer$Dir>";
static void *sprite_area;
//static void *er;
extern int quit = 0, foh_confirmed = 0, foh_conn_state = 0;
static char /*prompt_var[32],*/ *password;
/*static char const serial_dir[]="SerialDev:modules";*/
extern void foh_get_password(char *pw)
{
ER(writablefield_set_value(0, PasswordWin, 0, "\0"));
ER(toolbox_show_object(0, PasswordWin, 3, NULL, 0, 0));
password = pw;
}
/*static void write_in_icon(char *text)
{
WimpGetIconStateBlock b;
iconbar_get_icon_handle(0, IconBar, &b.icon_handle);
b.window_handle = -1;
wimp_get_icon_state(&b);
strcpy(b.icon.data.it.buffer, text);
}*/
extern void foh_change_status(char *text, char *sprite, char *toggle, int setup_grey)
{
/*char prefix[64]="Socketeer: ";*/
/*strcat(prefix, text);*/
ER(iconbar_set_text(0, IconBar, text));
/*ER(window_set_title(0, LauncherWin, prefix));*/
/*ER(displayfield_set_value(0, ControlWin, 4, text));*/
/*write_in_icon(text);*/
ER(iconbar_set_sprite(0, IconBar, sprite));
ER(menu_set_entry_text(0, ConnMenu, 0, toggle));
ER(actionbutton_set_text(0, ControlWin, 2, toggle));
ER(menu_set_fade(0, IconMenu, 3, setup_grey));
ER(gadget_set_flags(0, ControlWin, 4, setup_grey<<31));
}
static int foh_get_password_handler(void)
{
writablefield_get_value(0, PasswordWin, 0, password, 64, NULL);
connect_sendpassword();
return(1);
}
static void dialogue_poll(void)
{
if (read_time() > dialogue_timeout && dialogue_timeout != 0)
{
toolbox_hide_object(0, MessageWin);
dialogue_timeout = 0;
}
}
extern void foh_inform(char *text, int time)
{
ER(button_set_value(0, MessageWin, 0, text));
ER(actionbutton_set_text(0, MessageWin, 1, msgs_lookup("Bokay")));
ER(gadget_move_gadget(0, MessageWin, 3, &Q2_offscreen));
ER(toolbox_show_object(0, MessageWin, 3, NULL, 0, 0));
ER(actionbutton_set_event(0, MessageWin, 1, 0));
if (time != 0)
dialogue_timeout = read_time() + time;
}
extern void foh_question(char *text, char *c1, char *c2, int event1, int event2, int time)
{
// N.B. text is sent as text, the rest are message tokens
ER(button_set_value(0, MessageWin, 0, text));
ER(actionbutton_set_text(0, MessageWin, 1, msgs_lookup(c1)));
ER(actionbutton_set_text(0, MessageWin, 3, msgs_lookup(c2)));
ER(gadget_move_gadget(0, MessageWin, 3, &Q2_onscreen));
ER(toolbox_show_object(0, MessageWin, 3, NULL, 0, 0));
ER(actionbutton_set_event(0, MessageWin, 1, event1));
ER(actionbutton_set_event(0, MessageWin, 3, event2));
if (time != 0)
dialogue_timeout = read_time() + time;
else
dialogue_timeout = 0;
}
extern void foh_timer_control(enum timer_commands command)
{
switch (command)
{
case start :
timer_start_time = read_time(); break;
case stop :
timer_start_time = 0; break;
}
}
extern void foh_stats(int traffic_max, int traffic_val, int tx, int rx, int ping_max, int ping_val, int connect_speed)
{
int cmax, cval, x;
char txt[16];
ER(slider_get_bounds(1, StatsWin, 1, &cmax, &x, &x));
ER(slider_get_value(0, StatsWin, 1, &cval));
if (cmax != traffic_max && traffic_max != -1)
ER(slider_set_bounds(1, StatsWin, 1, traffic_max, 0, 1));
if (cval != traffic_val && traffic_val != -1)
{
ER(slider_set_value(0, StatsWin, 1, traffic_val));
sprintf(txt, "%d", traffic_val);
ER(displayfield_set_value(0, StatsWin, 4, txt));
}
ER(slider_get_bounds(1, StatsWin, 9, &cmax, &x, &x));
ER(slider_get_value(0, StatsWin, 9, &cval));
if (cmax != ping_max && ping_max != -1)
ER(slider_set_bounds(1, StatsWin, 9, ping_max, 0, 1));
if (cval != ping_val && ping_val != -1)
{
ER(slider_set_value(0, StatsWin, 9, ping_val));
sprintf(txt, "%d", ping_val);
ER(displayfield_set_value(0, StatsWin, 10, txt));
}
ER(displayfield_get_value(0, StatsWin, 2, txt, 16, &x));
if (atoi(txt) != tx && tx != -1)
{
sprintf(txt, "%d", tx);
ER(displayfield_set_value(0, StatsWin, 2, txt));
}
ER(displayfield_get_value(0, StatsWin, 6, txt, 16, &x));
if (atoi(txt) != rx && rx != -1)
{
sprintf(txt, "%d", rx);
ER(displayfield_set_value(0, StatsWin, 6, txt));
}
ER(numberrange_get_value(0, StatsWin, 0xd, &cval));
if (cval != connect_speed)
ER(numberrange_set_value(0, StatsWin, 0xd, connect_speed));
}
extern void foh_reflectcflags(int greyall, int sustain, int idle30)
{
int cgreyall, csustain, cidle30;
ER(menu_get_fade(0, ConnMenu, 1, &cgreyall))
if (greyall)
{
if (greyall != cgreyall)
{
ER(menu_set_fade(0, ConnMenu, 1, 1));
ER(menu_set_fade(0, ConnMenu, 2, 1));
ER(menu_set_fade(0, ConnMenu, 3, 1));
ER(menu_set_tick(0, ConnMenu, 2, 0));
ER(menu_set_tick(0, ConnMenu, 3, 0));
}
ER(toolbox_hide_object(0, StatsWin));
return;
}
else
{
if (greyall != cgreyall)
{
ER(menu_set_fade(0, ConnMenu, 1, 0));
ER(menu_set_fade(0, ConnMenu, 2, 0));
ER(menu_set_fade(0, ConnMenu, 3, 0));
}
}
ER(menu_get_tick(0, ConnMenu, 2, &csustain));
ER(menu_get_tick(0, ConnMenu, 3, &cidle30));
if (csustain != sustain)
ER(menu_set_tick(0, ConnMenu, 2, sustain));
if (cidle30 != idle30)
ER(menu_set_tick(0, ConnMenu, 3, idle30));
}
/*extern void foh_slider(int max, int val)
{
}*/
static void timer_update(void)
{
char time_text[12], time_text_cmp[12];
int elapsed=0;
if (CPC.assume_permanent)
return;
if (timer_start_time != 0)
elapsed = (read_time() - timer_start_time) / 100;
if (CPC.show_seconds)
sprintf(time_text, "%02d:%02d:%02d",
elapsed / 3600, (elapsed / 60) % 60, (elapsed % 60) );
else
sprintf(time_text, "%02d:%02d",
elapsed / 3600, (elapsed / 60) % 60);
/*ER(displayfield_get_value(0, ControlWin, 3, time_text_cmp, 12, NULL));
if (strcmp(time_text, time_text_cmp) != 0)
ER(displayfield_set_value(0, ControlWin, 3, time_text));*/
ER(iconbar_get_text(0, IconBar, time_text_cmp, 12, NULL));
if (strcmp(time_text, time_text_cmp) != 0 && timer_start_time != 0)
ER(iconbar_set_text(0, IconBar, time_text));
/*write_in_icon(time_text);*/
}
static char ic[3][12]={"online\0", "online_i\0", "online_p"};
static void icon_update(void)
{
char icon[12];
ER(iconbar_get_sprite(0, IconBar, icon, 12, NULL));
if (strcmp(icon, ic[foh_conn_state]) == NULL)
return;
ER(iconbar_set_sprite(0, IconBar, ic[foh_conn_state]));
}
void foh_complain(char *message)
{
_kernel_oserror error;
error.errnum = 0;
strcpy(error.errmess, message);
wimp_report_error(&error, 0, "Socketeer");
}
void foh_open_confirm(void)
{
ER(toolbox_show_object(0, DisconnWin, Toolbox_ShowObject_AtPointer, NULL, 0, 0));
}
static int foh_confirm_handler(void)
{
foh_confirmed = 1;
connect_toggle();
return(1);
}
void foh_idle_warn(int secs)
{
char str[8];
if (secs == -1)
{
toolbox_hide_object(0, IdleWin);
return;
}
sprintf(str, "%d", secs);
ER(displayfield_set_value(0, IdleWin, 1, str));
ER(toolbox_show_object(0, IdleWin, 3, NULL, 0, 0));
}
static int quit_handler(void)
{
quit = 1;
return(1);
}
static int data_load_handler(WimpMessage *message, void *h)
{
int w;
h=h;
ER(window_get_wimp_handle(0, SetupConnec, &w));
if (message->data.data_load.destination_window == w)
{
int i_on[2], i_off[2];
ER(gadget_get_icon_list(0, SetupConnec, 0x124, i_on, 8, NULL));
ER(gadget_get_icon_list(0, SetupConnec, 0x127, i_off, 8, NULL));
if (message->data.data_load.destination_icon == i_on[0])
setup_drag_to(ICON_ONLINE, message->data.data_load.leaf_name);
if (message->data.data_load.destination_icon == i_off[0])
setup_drag_to(ICON_OFFLINE, message->data.data_load.leaf_name);
}
return(1);
}
static int quick_connect_handler(void)
{
connect_toggle();
return(1);
}
static int iconbar_adjust_handler(void)
{
if (connect_state == offline)
{
connect_toggle();
return(1);
}
if (!CPC.adjust_stats)
connect_toggle();
else
ER(toolbox_show_object(0, StatsWin, Toolbox_ShowObject_AtPointer, NULL, 0, 0));
return(1);
}
static int show_log(void)
{
system("Filer_Run <Choices$Dir>.Socketeer.Log");
return(1);
}
static int autocreate_handler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *h)
{
ToolboxObjectAutoCreatedEvent *event_a;
char serial_drivers[1024];
int x=0, drivers, num=0;
h=h; event_code=event_code;
event_a = (ToolboxObjectAutoCreatedEvent*) event;
if (strcmp(event_a->template_name, "AddWin") == 0)
AddWin = id_block->self_id;
if (strcmp(event_a->template_name, "ConnMenu") == 0)
{
ConnMenu = id_block->self_id;
ER(event_register_toolbox_handler(-1, 0x500, (ToolboxEventHandler*) connect_toggle_cflags_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x501, (ToolboxEventHandler*) connect_toggle_cflags_handler, NULL));
foh_reflectcflags(1, 0, 0);
}
if (strcmp(event_a->template_name, "FriendsWin") == 0)
FriendsWin = id_block->self_id;
if (strcmp(event_a->template_name, "DisconnWin") == 0)
DisconnWin = id_block->self_id;
if (strcmp(event_a->template_name, "ControlWin") == 0)
{
ControlWin = id_block->self_id;
ER(stringset_set_available(0, ControlWin, 4, setup_stringset));
ER(stringset_set_selected(0, ControlWin, 4, connect_profile_current_name));
foh_stats(CPC.serial_speed >> 3, 0, 0, 0, CPC.pings_disconnect, 0, 0);
}
if (strcmp(event_a->template_name, "IconBar") == 0)
IconBar = id_block->self_id;
if (strcmp(event_a->template_name, "IconMenu") == 0)
IconMenu = id_block->self_id;
if (strcmp(event_a->template_name, "IdleWin") == 0)
IdleWin = id_block->self_id;
if (strcmp(event_a->template_name, "LauncherWin") == 0)
{
LauncherWin = id_block->self_id;
launcher_init();
ER(event_register_wimp_handler(LauncherWin, -1, launcher_event_handler, NULL));
}
if (strcmp(event_a->template_name, "MessageWin") == 0)
{
MessageWin = id_block->self_id;
ER(gadget_get_bbox(0, MessageWin, 3, &Q2_onscreen));
Q2_offscreen.xmin = Q2_offscreen.ymin =
Q2_offscreen.xmax = Q2_offscreen.ymax = -1000;
}
if (strcmp(event_a->template_name, "PasswordWin") == 0)
PasswordWin = id_block->self_id;
if (strcmp(event_a->template_name, "ProgInfo") == 0)
{
ProgInfo = id_block->self_id;
proginfo_set_version(0, ProgInfo, VERSION);
}
if (strcmp(event_a->template_name, "RenameWin") == 0)
RenameWin = id_block->self_id;
if (strcmp(event_a->template_name, "SetupAccoun") == 0)
{
SetupAccoun = id_block->self_id;
ER(event_register_toolbox_handler(SetupAccoun, RadioButton_StateChanged, setup_pwradio_handler, NULL));
}
if (strcmp(event_a->template_name, "SetupConnec") == 0)
SetupConnec = id_block->self_id;
if (strcmp(event_a->template_name, "SetupEther") == 0)
{
char v[256], *b;
SetupEther = id_block->self_id;
ER(event_register_toolbox_handler(SetupEther, OptionButton_StateChanged, (ToolboxEventHandler*) setup_perm_toggle, NULL));
if (getenv("Socketeer$DCI4Drivers") != NULL) {
strcpy(v, getenv("Socketeer$DCI4Drivers"));
for (b=v; *b!=0; b++)
if (*b == ' ') *b=',';
ER(stringset_set_available(0, SetupEther, SETUPETHER_DRIVER, v+1));
}
//strcpy(v, getenv("Socketeer$DCI4
}
if (strcmp(event_a->template_name, "SetupFE") == 0)
SetupFE = id_block->self_id;
if (strcmp(event_a->template_name, "SetupFinger") == 0)
SetupFinger = id_block->self_id;
if (strcmp(event_a->template_name, "SetupTCPIP") == 0)
SetupTCPIP = id_block->self_id;
if (strcmp(event_a->template_name, "SetupLaunch") == 0)
SetupLaunch = id_block->self_id;
if (strcmp(event_a->template_name, "SetupModem") == 0)
{
SetupModem = id_block->self_id;
drivers = read_entries("SerialDev:Modules", serial_drivers, 1024);
for (; num != drivers; x++)
if (serial_drivers[x] < 32)
{ serial_drivers[x] = ','; num++; }
serial_drivers[x-1] = 0;
stringset_set_available(0, SetupModem, 0x100, serial_drivers);
}
if (strcmp(event_a->template_name, "SetupWin") == 0)
{
SetupWin = id_block->self_id;
ER(event_register_toolbox_handler(-1, StringSet_ValueChanged, setup_load_new_profile, NULL));
if (getenv("Socketeer$DCI4Drivers") == NULL) {
ER(gadget_set_flags(1<<31, SetupWin, SETUP_SETHER, 1<<31))
}
}
if (strcmp(event_a->template_name, "StatsWin") == 0)
{
StatsWin = id_block->self_id;
}
if (StatsWin && IconBar && ControlWin && !first_time_init)
{
first_time_init = 1;
connect_init_new_profile();
}
return(1);
}
/*static int create_objects(void)
{
_kernel_oserror *e;
if (
(e=toolbox_create_object(0, "AddWin", &AddWin)) != NULL ||
(e=toolbox_create_object(0, "FriendsWin", &FriendsWin)) != NULL ||
(e=toolbox_create_object(0, "IconBar", &IconBar)) != NULL ||
(e=toolbox_create_object(0, "IdleWin", &IdleWin)) != NULL ||
(e=toolbox_create_object(0, "LauncherWin", &LauncherWin)) != NULL ||
(e=toolbox_create_object(0, "ControlWin", &ControlWin)) != NULL ||
(e=toolbox_create_object(0, "MessageWin", &MessageWin)) != NULL ||
(e=toolbox_create_object(0, "PasswordWin", &PasswordWin)) != NULL ||
(e=toolbox_create_object(0, "ProgInfo", &ProgInfo)) != NULL ||
(e=toolbox_create_object(0, "RenameWin", &RenameWin)) != NULL ||
(e=toolbox_create_object(0, "SetupAccoun", &SetupAccoun)) != NULL ||
(e=toolbox_create_object(0, "SetupConnec", &SetupConnec)) != NULL ||
(e=toolbox_create_object(0, "SetupTCPIP", &SetupTCPIP)) != NULL ||
(e=toolbox_create_object(0, "SetupLaunch", &SetupLaunch)) != NULL ||
(e=toolbox_create_object(0, "SetupModem", &SetupModem)) != NULL ||
(e=toolbox_create_object(0, "SetupWin", &SetupWin)) != NULL ||
(e=toolbox_create_object(0, "StatsWin", &StatsWin)) != NULL
)
{
wimp_report_error(e, 0, "Socketeer");
return(0);
}
return(1);
}*/
static int null_event(void)
{
dialogue_poll();
connect_poll();
timer_update();
if (connect_state == online)
icon_update();
return(1);
}
int main(void)
{
FILE *fh;
int event_code;
WimpPollBlock poll_block;
char /*last_profile[256], */var[256], last_valid[12], *opts;
opts = get_command_line();
debug_flags.notimeouts = (strstr(opts, "-notimeouts") != NULL);
debug_flags.debuglog = (strstr(opts, "-debuglog") != NULL);
debug_flags.noresconf = (strstr(opts, "-noresconf") != NULL);
if (debug_flags.debuglog) debug_init();
debug_log("Socketeer v%s started", VERSION);
/*MemCheck_Init();
MemCheck_InterceptSCLStringFunctions();*/
/*HierProf_ProfileAllFunctions();*/
debug_log("Registering event / message handlers");
ER(event_register_message_handler(0, (WimpMessageHandler*) quit_handler, NULL));
ER(event_register_message_handler(Wimp_MDataLoad, data_load_handler, 0));
ER(event_register_toolbox_handler(-1, 0x100, (ToolboxEventHandler*) quit_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x110, (ToolboxEventHandler*) quick_connect_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x113, (ToolboxEventHandler*) iconbar_adjust_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x111, (ToolboxEventHandler*) foh_get_password_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x112, (ToolboxEventHandler*) show_log, NULL));
ER(event_register_toolbox_handler(-1, 0x200, setup_open_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x201, setup_open_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x210, (ToolboxEventHandler*) setup_add_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x211, (ToolboxEventHandler*) setup_rename_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x212, (ToolboxEventHandler*) setup_delete_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x213, (ToolboxEventHandler*) setup_save_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x214, (ToolboxEventHandler*) setup_open_launcher, NULL));
ER(event_register_toolbox_handler(-1, 0x215, setup_edit_file, NULL));
ER(event_register_toolbox_handler(-1, 0x300, add_rename_confirm_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x301, add_rename_confirm_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x400, (ToolboxEventHandler*) foh_confirm_handler, NULL));
ER(event_register_toolbox_handler(-1, 0x401, (ToolboxEventHandler*) connect_extend_idle, NULL));
ER(event_register_toolbox_handler(-1, Toolbox_ObjectAutoCreated, autocreate_handler, NULL));
ER(event_register_wimp_handler(-1, Wimp_ENull, (WimpEventHandler*) null_event, NULL));
ER(event_set_mask(!Wimp_Poll_NullMask | Wimp_Poll_KeyPressedMask));
debug_log("Registering with toolbox");
ER(toolbox_initialise(0, 310, &interested, &interested, directory, &msg_block,
&id_block, ¤t_wimp, &task_handle, &sprite_area));
debug_log("Registering with event lib");
ER(event_initialise(&id_block));
/*if (!create_objects())
{
foh_complain("Couldn't create Toolbox objects");
exit(1);
} */
debug_log("Starting ping library");
if (ping_init() != 0)
{
foh_complain(msgs_lookup("Epingprob"));
exit(1);
}
debug_log("Loading last configuration");
fh = fopen("<Choices$Dir>.Socketeer.Last", "rb");
if (fh == NULL)
setup_read_profiles(1);
else
{
fgets(last_valid, 12, fh);
sprintf(var, "<Choices$Dir>.Socketeer.Profiles.%s", last_valid);
setup_read_profiles(!file_exists(var));
if (file_exists(var))
strcpy(connect_profile_current_name, last_valid);
fclose(fh);
}
var_read("PPP$Choose", var);
if (strcmp(var, "Sergio") == 0)
ppp_module = sergio;
else
ppp_module = acorn;
foh_timer_control(stop);
setup_load(connect_profile_current_name);
connect_read_responses();
debug_log("Starting main loop");
while (!quit)
event_poll_idle(&event_code, &poll_block, read_time()+50, NULL);
debug_log("Saving last configuration");
fh = fopen("<Choices$Dir>.Socketeer.Last", "w");
if (fh != NULL)
{
fputs(connect_profile_current_name, fh);
fclose(fh);
}
debug_log("The End");
}